<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Server\GoodsServer;
use App\Services\JsonResponseService;
use Illuminate\Http\Request;

class GoodsController extends Controller
{
    //产品管理
    public function __construct() {
        $this->server = new GoodsServer();
    }

    /**
     * 添加产品
     * @param Request $request
     */
    public function addGoods(Request $request){
        $id = $request->input('id');
        $goods_name = $request->input('goods_name');
        $manufacturer_id = $request->input('manufacturer_id');
        $inventory = $request->input('inventory');
        $cost_price = $request->input('cost_price');
        $sales_price = $request->input('sales_price');
        $res = $this->server->addGoodsServer($id,$goods_name,$manufacturer_id,$inventory,$cost_price,$sales_price);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

    /**
     * 获取产品列表
     */
    public function getGoodsList(Request $request){
        // 获取查询条件
        $params = $request->only(['goods_name', 'manufacturer_id']);
        $per_page = $request->input('per_page');
        $res = $this->server->getGoodsListServer($params,$per_page);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }
}
